package com.hlxl.viewpointrest.filter;

import com.hlxl.viewpointrest.dto.ErrorMsgDTO;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by wyy on 18-5-8
 */
@RestControllerAdvice
public class CustomExceptionHandler {

    @ExceptionHandler(value = {SecurityException.class})
    public ErrorMsgDTO securityException(SecurityException exception, HttpServletRequest request, HttpServletResponse response) {
        response.setStatus(555);
        ErrorMsgDTO errorMsgDTO = new ErrorMsgDTO("101", exception.getMessage(), "no permission", request.getServletPath());
        return errorMsgDTO;
    }
}
